package javabase.desginpattern.behavior.observer.push;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fance
 * @date 18-4-26 下午4:05
 */
public abstract class AbstractSubject {

    private List<Observer> list = new ArrayList<>();
    public void attach(Observer observer) {
        list.add(observer);
    }
    public void detach(Observer observer) {
        list.remove(observer);
    }

    public void notifyObservers(String s) {
        int len = list.size();
        for (int i = 0; i < len; i++) {
            list.get(i).update(s);
        }
    }
}
